home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / DDEPASCAL / DDE / !PC / README < prev    next >
Text File  |  1992-05-05  |  40KB  |  1,173 lines

  1. Introduction
  2. ============
  3.  
  4. !PC is an ISO Level 1 Pascal compiler. It is designed to be used with
  5. the desktop development environment supplied with Desktop C. It may
  6. be used to generate RISC OS desktop applications or relocatable
  7. modules written in Pascal.
  8.  
  9. The Pascal compiler contains a number of language extensions to
  10. overcome limitations in the ISO Pascal standard and to allow RISC OS
  11. applications to be written in Pascal.
  12.  
  13. A set of header files is provided which allow Pascal programs to be
  14. linked with the RISC_OSLib library provided with Desktop C.
  15.  
  16. The Pascal run time library is provided in two variants, one for
  17. linking applications and the second for linking modules. The Pascal
  18. run time library calls the C library so programs written in Pascal
  19. must be linked with either the unshared library ANSILib or the shared
  20. library Stubs.
  21.  
  22. An example desktop program !Balls64 is included. This is a conversion
  23. of the !Balls64 program provided with Desktop C.
  24.  
  25. Installation
  26. ------------
  27.  
  28. To install !PC to a hard disc simply copy the !PC directory into the
  29. DDE directory on your hard disc.
  30.  
  31. Copy the following lines to your !Make.choices.tools file in the DDE
  32. directory.
  33.  
  34. ------------------------------------
  35. PC
  36. p
  37. -c -depend !Depend -throwback -IP:
  38. pc $(pcflags) -o $@ $<
  39. DDE:!PC.desc
  40. DDE:!PC.!setup
  41. ------------------------------------
  42.  
  43. Installing for command line use
  44. -------------------------------
  45.  
  46. If you wish to use the Pascal compiler from the command line
  47. copy/rename the file !PC.PC to your library directory and add the
  48. following line to your !Boot.
  49.  
  50. %Obey <DDE directory>.!PC.!Boot
  51.  
  52. Where <DDE directory> is substituted with the full pathname of your
  53. DDE directory. This sets up the variables P$LibRoot and P$Path which
  54. are used by the Pascal compiler to locate the pascal library and the
  55. RISC_OSLib Pascal headers.
  56.  
  57. Using the Pascal compiler from the command line is described in the
  58. section "The command line".
  59.  
  60. Using !PC
  61. =========
  62.  
  63. To start !PC double click on the !PC application. This will place the
  64. !PC icon on the icon bar.
  65.  
  66. Click Select on the !PC icon, this will open a setup dialog box
  67. containing a single writeable icon labelled "Source:", a number
  68. of option icons and two action icons labelled "Run" and "Cancel".
  69.  
  70. To compile a Pascal program drag the Pascal source to the Source
  71. icon and click Run. Note the Pascal source must be stored in a
  72. directory called "p", this is to allow !Make to differentiate between
  73. C and Pascal sources.
  74.  
  75. If the program compiles successfully a "Save" dialog box will be
  76. displayed containing an icon representing the compiled image. Drag
  77. this to a directory viewer and run it by double clicking on it.
  78.  
  79. If errors are encountered in the source the errors will be listed in a
  80. window. If you are using the editor !SrcEdit and the "Throwback"
  81. option is enabled the errors will also be displayed in a "Throwback"
  82. window. Double clicking on an error in the Throwback will cause
  83. !SrcEdit to open the source file containing the error at the line
  84. which generated the error, this line will be highlighted for clarity.
  85.  
  86. If you have more than one source file to compile drag all the source
  87. files to the "Source" icon and click Run. All the source files will
  88. be compiled in turn and then linked together to produce a single
  89. executable. Note: standard Pascal does not allow you to write your
  90. programs in separate source units, !PC allows this by means of
  91. language extensions described in the section "Language extensions".
  92.  
  93. Setup dialog box options
  94. ------------------------
  95.  
  96. Compile only:
  97.  
  98. Usually when !PC is used to compile a Pascal program it automatically
  99. runs the linker to bind your program with the Pascal run time library.
  100. This option can be used to prevent the link step from happening. You
  101. may want to do this if you have a number of Pascal sources which you
  102. wish to compile separately. You should place such files in a
  103. directory called "o" so that !PC and !Make can differentiate between
  104. pre-compiled object files and source files.
  105.  
  106. To link object files generated this way drag the object files to the
  107. Source icon and click Run. !PC will notice that they are pre-compiled
  108. object files (because they are stored in the "o" directory) and will
  109. just perform the necessary link step. (You can drag any mixture of
  110. source and object file in, !PC will perform the appropriate action
  111. on each and then link them all).
  112.  
  113. Assembler output:
  114.  
  115. Use this option if you wish to examine the assembler code generated
  116. by the compiler.
  117.  
  118. ISO:
  119.  
  120. If this option is enabled !PC will compile strictly according to the
  121. Pascal standard as described in BS 6192 : 1982.
  122.  
  123. Debug:
  124.  
  125. If this option is enabled !PC will generate an image suitable for
  126. use with the desktop debugger !DDT. The debugging facilities provided
  127. by DDT are limited in certain ways when debugging Pascal programs,
  128. these limitations and debugging in general are described in the
  129. section "Pascal and DDT".
  130.  
  131. Throwback:
  132.  
  133. If this option is enabled and the editor !SrcEdit is loaded errors
  134. in compilation are listed in a Throwback window. This window can
  135. be use to rapidly locate and correct errors in your program.
  136.  
  137. This option is enabled by default.
  138.  
  139. Uses RISC_OSLib:
  140.  
  141. This option should be selected if your pascal program makes any calls
  142. to RISC_OSLib library functions. It cause the compiler to instruct the
  143. linker to include RISC_OSLib in the list of libraries to be searched.
  144.  
  145. Run time checks:
  146.  
  147. These options enable or disable the generation of run time checking
  148. code which is inserted in the generated code. When developing
  149. a program you will probably wish to leave all these options enabled.
  150. For the final compilation, however, you may wish to disable some or
  151. all of the run time checks to reduce code size and improve
  152. performance.
  153.  
  154. Array bounds:
  155.  
  156. This option inserts code to check that array accesses do not exceed
  157. their array bounds.
  158.  
  159. Nil pointers:
  160.  
  161. This option inserts code to check that Nil pointers are not
  162. dereferenced.
  163.  
  164. Variable references:
  165.  
  166. This option inserts code to check that variables are assigned before
  167. being referenced.
  168.  
  169. Assertion statements:
  170.  
  171. One of the language extensions described in the section "Language
  172. extensions" is an "assert" statement which allows you to insert
  173. your own checks in your code. If this option is enabled the compiler
  174. will compile these assert statements. If the option is disabled such
  175. statements will not be compiled and no extra code will be generated.
  176.  
  177. Setup menu options
  178. ------------------
  179.  
  180. Other less commonly used options may be accessed from the menu
  181. on the setup dialog box. These options are as follows.
  182.  
  183. Command line:
  184.  
  185. This option allows you to examine and/or change the command line
  186. generated by the !PC frontend which is used to run the Pascal
  187. compiler. When you change the command line and wish to execute the
  188. changed command click on the Run icon in the Command line dialog box.
  189. Once you move off the Command line dialog box onto the setup menu
  190. the changed command line will be forgotten and the original command
  191. line (as constructed by the !PC tool) will be reconstructed.
  192.  
  193. No warnings:
  194.  
  195. Supresses the generation of warning messages.
  196.  
  197. Module code:
  198.  
  199. This options must be enabled when compiling code to be used to
  200. generate a RISC OS relocatable module using the CMHG tool. For
  201. more information on writing relocatable modules in Pascal refer
  202. to the section "Writing relocatable modules in Pascal"
  203.  
  204. Profile:
  205.  
  206. This option enables the generation of code which is suitable for
  207. use with the ANSILib functions _mapstore and _fmapstore. This
  208. code counts the number of times each function or block of code
  209. is executed. _mapstore and _fmapstore output the profiling
  210. information to the screen or to a named file respectively. For
  211. details on how to call _mapstore or _fmapstore from Pascal refer
  212. to the section "Language extensions".
  213.  
  214. Preprocess only:
  215.  
  216. The compiler uses a pre-processor (similar to the C pre-processor)
  217. before performing the actual compilation. This option disables the
  218. compilation and just runs the pre-processor on the source file. The
  219. pre-processed output is displayed in the compilation window.
  220.  
  221. Include:
  222.  
  223. When searching for "include" files (described in the section
  224. "Language extension") the compiler usually search the path P:
  225. (ie the setting of the variable P$Path). You can use this option
  226. to change where the compiler searches for header files.
  227.  
  228. Keep comments:
  229.  
  230. Normally when pre-processing the compiler removes any comments in
  231. the source code. If this option is enabled the pre-processor will
  232. not remove comments.
  233.  
  234. Libraries:
  235.  
  236. This option specifies a list of libraries to be searched when linking.
  237. These libraries are in addition to the default Pascal run time
  238. library ("P:o.PLib"). By default this option is set to
  239. "C:o.RISC_OSLib,C:o.stubs".
  240.  
  241. Pascal programs must be linked with the C library as the Pascal run
  242. time library calls the C library. By default they are linked with
  243. the shared library Stubs. You can change this using this option to
  244. link with the unshared ANSILib instead, if, for example you wish to
  245. use the _mapstore or _fmapstore functions which are not included in
  246. shared library or if you wish to use the overlay manager in the
  247. unshared library.
  248.  
  249. Predefine:
  250.  
  251. The pre-processor allows you to define symbols which can be used to
  252. conditionally compile sections of code. The use of pre-processor
  253. symbols is described in the section "Language extensions". You may
  254. wish to use this option if, for example, you have code which displays
  255. debugging information which you would not normally wish to have
  256. compiled unless you are trying to debug the program.
  257.  
  258. Undefine:
  259.  
  260. The compiler automatically defines some pre-processor symbols on
  261. startup. These symbols are listed in the section "Language
  262. extensions". This option allows you to undefine any or all of
  263. the symbols.
  264.  
  265. Work directory:
  266.  
  267. This option allows you to change the "Work directory" used by !PC.
  268. The concept of a work directory is explained in the section
  269. "File naming and placing" in the Desktop C manual.
  270.  
  271. Other:
  272.  
  273. This allows you to specify other options to the underlying command
  274. line compiler. These options have not been included in the setup
  275. dialog because they are obscure and rarely used. A list of these
  276. options is given in the section "The command line".
  277.  
  278. Language extensions
  279. ===================
  280.  
  281. Identifiers
  282.  
  283. Identifiers may start with and contain underscores. There is no limit
  284. on identifier length and all characters are significant.
  285.  
  286. Files
  287.  
  288. Input and output need not appear in the program header. `File of char'
  289. and `packed file of char' are treated as equivalent to `text'. Lazy
  290. evaluation is performed on files opened for input. In the absence of
  291. explicit file bindings (see reset and rewrite in the section on
  292. library extensions) external files are bound to a filename
  293. corresponding to the file identifier in the current directory, input
  294. and output are bound to the equivalent of C stdin and stdout streams
  295. (normally the keyboard and screen). Files are buffered, on a read
  296. request from input the output buffer is flushed. 
  297.  
  298. Strings
  299.  
  300. Strings are blank padded or truncated in expressions and as value
  301. parameters to fit the required size. Strings may be of length 1. The
  302. null string '' is permitted. The packed attribute may be omitted in a
  303. string declaration.
  304.  
  305. Pascal strings are zero terminated, the compiler adds one byte to the
  306. allocation space of the string and initialises this byte to zero when
  307. the string is assigned. Thus Pascal strings may be used in calls to
  308. external functions written in C.
  309.  
  310. The predefined type string is equivalent to the C `char *' and may be
  311. used in external calls to C.  Variables of type string are compatible
  312. with Pascal strings and may be used in assignments and expressions and
  313. as value parameters. Note that no space is allocated for a variable of
  314. type string, space must be allocated either by assignment or by
  315. explicit allocation using, for example, malloc.
  316.  
  317. The predefined type alpha = packed array[1..10] of char is intended
  318. for use with the extended Pascal library, for example, date and time.
  319. See the section on library extensions.
  320.  
  321. Procedures and functions
  322.  
  323. Procedures may return values, these are declared like functions with
  324. the keyword procedure substituted for function. Value returning
  325. procedures may be called in a procedure or function context.  This is
  326. intended for use with external functions which return error codes
  327. which are not generally checked, for example, putchar.
  328.  
  329. Procedures and functions may return records, like pointers these may
  330. not be immediatly referenced but must be assigned to a variable.
  331.  
  332. Variadic functions may be declared by placing a .. as the last
  333. parameter. Variadic arguments may be accessed using the address and
  334. size functions (see the section on library extensions) however the
  335. intended purpose is for declaring external variadic functions, for
  336. example, printf.
  337.  
  338. Procedure and functions pointers may be declared, these are declared
  339. by placing a `^' before a procedure or function declaration in a type
  340. declaration, note that the procedure or function must be given a name
  341. and all parameters must be named. Only top level and external
  342. procedures or functions may be be assigned to a procedure or function
  343. pointer. Procedure and function pointers are intended for use with
  344. external procedures or functions which take or return procedure or
  345. function pointers, for example, signal.
  346.  
  347. External objects
  348.  
  349. Procedures, functions and variables may be declared external or global
  350. by placing extern; or external; after the declaration (like forward is
  351. used for declaring forward referenced procedures or functions).  Such
  352. objects are taken to be external if there is no definition of the
  353. object in the same module and global if there is a definition. Objects
  354. declared external use the case of the external declaration identifier.
  355. External declarations are case sensitive between modules and case
  356. insensitive within a single module. The program heading may be omitted
  357. to create a module containing only procedure and functions and/or
  358. variables. No mainline may be given if the program heading is omitted.
  359.  
  360. The recommended way to use external declarations is to create a header
  361. file (ending with `.h') containing the external declarations and use
  362. the #include mechanism provided by the C preprocessor to include this
  363. header in both the module defining the object and the module
  364. referencing the object. This insures type correctness between modules.
  365. Note that the filename after the #include must be enclosed in double
  366. quotes not single quotes.
  367.  
  368. Type casts
  369.  
  370. For each pointer, ordinal or file type declared a cast function of the
  371. same name is automatically declared which casts a pointer, ordinal or
  372. file variable to the declared type.
  373.  
  374. Constants
  375.  
  376. Constant expressions may be used in const declarations. The following
  377. functions may be used in constant expressions if they have constant
  378. arguments: shl, shr, uand, uor, uxor, unot, trunc, ord, chr, succ,
  379. pred, odd, and undefined.
  380.  
  381. Declarations
  382.  
  383. Multiple Label, Const, Type and Variable declarations sections may be
  384. given within a single block. Label, Const, Type, Variable, Procedure
  385. and Function declarations may occur in any order.
  386.  
  387. Predefined types
  388.  
  389. string = ^char - This type is compatible with Pascal strings and is
  390. intended for use with with external library functions which require a
  391. C style string.
  392.  
  393. alpha = packed array[1..10] of char - This type is used with the
  394. extended library functions time and date.
  395.  
  396. pointer - This is a generic pointer type compatible with all other
  397. pointer types. It is equivalent to the C void * type.
  398.  
  399. byte - This is a one byte long signed integer type.
  400.  
  401. short - This is a half word long signed integer type.
  402.  
  403. word - This is a word long unsigned integer type.
  404.  
  405. error - Variables of this type may be used to hold pointers to RISC OS
  406. errors. These variables are compatible with the with the Pascal type
  407. boolean yielding True if the variable points to RISC OS error block.
  408.  
  409. Operators
  410.  
  411. The additional operators `&' and `|' are provided. These are
  412. functionally identical to and and or.
  413.  
  414. Preprocessor
  415. ------------
  416.  
  417. The Pascal compiler invokes the C preprocessor on the Pascal source
  418. before compiling it. A complete description of the C preprocessor
  419. is not given here.
  420.  
  421. #include "<header>.h"
  422.  
  423. This reads a header file "h.<header>" into your Pascal source. Header
  424. files are used to contain inter module definitions when writing
  425. multiple module Pascal programs. A standard set of headers is provided
  426. for use with modules in the library RISC_OSLib. See the example
  427. program !Balls64 for examples of how to use RISC_OSLib.
  428.  
  429. Header files are searched for first in the current directory, then in
  430. the directory <P$LibRoot>. By default <P$LibRoot> is set to P:. This
  431. causes the compiler to search the directory specified by the comma
  432. separated list of directories in P$Path. This is set up by the !PC
  433. application to point to the directory containing the RISC_OSLib
  434. headers.
  435.  
  436. #define <symbol> [<expansion>]
  437.  
  438. This defines a simple symbol expansion. The <symbol> is replaced with
  439. its expansion when it occurs in your source. If <expansion> is omitted
  440. the following default is used.
  441.  
  442. #define <symbol> 1
  443.  
  444. #define <macro>(<arg1>, <arg2>, ...) <macro expansion>
  445.  
  446. This defines a macro expansion. When a function or procedure call is
  447. made which corresponds to the macro definition the macro is expanded.
  448. Arguments <arg1>, <arg2>, ... are replaced where they occur in the
  449. macro expansion.
  450.  
  451. #undef <symbol>|<macro>
  452.  
  453. Removes a symbol or macro definition.
  454.  
  455. #ifdef <symbol>
  456. #else
  457. #endif
  458.  
  459. This construct may be used to conditionally compile section of code.
  460. If the preprocessor symbol <symbol> is defined the code between
  461. the #ifdef <symbol> and the #else is compiled, otherwise the code
  462. between the #else and the #endif is compiled. The #else clause may
  463. be omitted.
  464.  
  465. The use of the C preprocess #if is not supported.
  466.  
  467. #error <text of error>
  468.  
  469. Causes compilation to stop printing <text of error>. This may be
  470. used when conditionally compiling code for different architectures or
  471. operating systems, for example,
  472.  
  473. #ifdef BIG_ENDIAN
  474. #error This code must be modified to run on a big endian machine
  475. #endif
  476.  
  477. #pragma -<letter>[<digit>]
  478. #pragma [no_]<pragma>
  479.  
  480. Pragmas may be specified in two forms, a long form and a short form.
  481. The following pragmas are recognised.
  482.  
  483. long form                       short form      negative short form
  484. ---------                       ----------      -------------------
  485. check_memory_accesses              -c1                  -c0
  486. continue_after_hash_error          -e1                  -e0
  487. profile                            -p1                  -p0
  488. check_stack                        -s0                  -s1
  489.  
  490. check_memory_accesses           (default = off)
  491.  
  492. This tells the compiler to insert code to check that memory accesses
  493. (via pointers or arrays) are within the application space allocated
  494. to the application.
  495.  
  496. continue_after_hash_error       (default = off)
  497.  
  498. This tells the compiler to continue compilation after it encounters
  499. a #error statement.
  500.  
  501. profile                         (default = off)
  502.  
  503. This pragma tells the compiler to insert code to count the number of
  504. times each procedure or function is called. To display the count
  505. insert a call to _mapstore or _fmapstore at the end of your program.
  506.  
  507. check_stack                     (default = on)
  508.  
  509. This pragma tells the compiler to insert code to check that the stack
  510. limit has not been exceeded in each procedure / function entry. The
  511. code checks that the procedure / function has enough stack to execute
  512. to completion and will try to extend the stack if this is not the
  513. case.
  514.  
  515. check_stack must be disabled around signal handlers which deal with
  516. stack overflow.
  517.  
  518. Library extensions
  519. ------------------
  520.  
  521. address(x) : pointer
  522.  
  523. Returns the address of variable access x.
  524.  
  525. argc : integer
  526.  
  527. Returns the number of command line arguments to the program including
  528. the program name (ie argc is always at least 1).
  529.  
  530. argv(i, a)
  531.  
  532. where i is an integer expression in range 0 to argc and a is a string
  533. variable. If a is of type string then the C expression argv[i] is
  534. assigned directly to a (ie a will point directly into the argv array
  535. and should not therefore be modified otherwise the contents of argv[i]
  536. are copied (possibly blank padded or truncated) to a.
  537.  
  538. assert(x[, a])
  539.  
  540. where x is a boolean expressions and a is an optional string
  541. expression (typically explaining why the assertion might have failed).
  542. The assert call checks the value of x and if it is false generates a
  543. run time error giving the file and line number where the assertion
  544. failed. The reason string a is also printed if given in the assert
  545. call. Calls to the assert function must be enabled with the -rp option
  546. on the command line.
  547.  
  548. byte_offset(t, f) : integer
  549.  
  550. t is the name of a record type, f is the name of a field within that
  551. record. Returns the offset (in bytes) of field f within a variable of
  552. record type t.
  553.  
  554. card(s) : integer
  555.  
  556. where s is a set expression returns the number of elements in s.
  557.  
  558. close(f)
  559.  
  560. where f is a file variable close the file bound to f, deallocates all
  561. buffers associated with f and frees f for reallocation.
  562.  
  563. clock : integer
  564.  
  565. returns the number of milliseconds elapsed since this program started.
  566.  
  567. date(a)
  568.  
  569. where a is a variable of type alpha assigns the current date to a in
  570. the form `dd mmm yy'.
  571.  
  572. flush(f)
  573.  
  574. flushes any output buffered for file f into its associated file
  575. binding.
  576.  
  577. halt
  578.  
  579. stops execution and returns control to the parent process with a
  580. return code of 0.
  581.  
  582. iaddress(x) : integer
  583.  
  584. Returns the address of variable access x as an integer. This is
  585. equivalent to integer(address(x)).
  586.  
  587. ignore(x)
  588.  
  589. where x is an expression of any type. Does nothing.
  590.  
  591. linelimit(f, x)
  592.  
  593. where f is a variable of type text and x is and integer expression.
  594. Limits the number of lines of output to file f to x. If x is less than
  595. 0 no limit is imposed. By default no limit is imposed. These limits
  596. are ignored by the current release.
  597.  
  598. message(...)
  599.  
  600. This is equivalent to writeln(...) except it writes to the unbuffered
  601. error stream stderr.
  602.  
  603. null
  604.  
  605. Does nothing.
  606.  
  607. random(x) : real
  608.  
  609. where x is a real expression which is evaluated but otherwise ignored
  610. returns a random number between 0.0 and 1.0 inclusive.  random uses a
  611. linear congruential random number generator. Successive seeds are
  612. generated as (seed * 62605 + 113218009) mod 536870912. The initial
  613. seed is 7774755. The `random' numbers generated by this method are not
  614. very random, the preferred method is to use the external function
  615. rand.
  616.  
  617. read(..., a, ...)
  618.  
  619. readln(..., a, ...)
  620.  
  621. where a is a string variable reads the remainder of the text line into
  622. a. The text line is blank padded or truncated to fit the string. If
  623. the variable is of type string it is assumed that it is pointing to an
  624. allocated area large enough to hold the current line.
  625.  
  626. remove(a)
  627.  
  628. where a is a string expression removes the file whose name is a
  629. (with trailing blanks removed).
  630.  
  631. reset(f, a)
  632.  
  633. where f is a file variable and a is a string expression associates the
  634. filename f with the file variable and opens that file for reading.
  635. Note that there is no way of detecting an error opening a file (eg.
  636. file not found). To do this use the external function fopen.
  637.  
  638. rewrite(f, a)
  639.  
  640. Similarly to reset, the two argument form of rewrite allows a filename
  641. to be bound to a file variable except the file is opened for writing
  642. instead of reading.
  643.  
  644. seed(x) : integer
  645.  
  646. where x is an integer expression sets the current random number
  647. generator seed to x and returns the value of the previous seed.
  648.  
  649. shl(x1, x2) : integer
  650.  
  651. where x1 and x2 are integers returns x1 shifted left x2 times. This is
  652. equivalent to x1 << x2 in C.
  653.  
  654. shr(x1, x2) : integer
  655.  
  656. where x1 and x2 are integers returns x1 shifted right x2 times. This
  657. is equivalent to x1 >> x2 in C.
  658.  
  659. size(x) : integer
  660.  
  661. where x is a variable access returns the size of variable access x in
  662. bytes.
  663.  
  664. stlimit(x)
  665.  
  666. where x is an integer expression limits the number of statements that
  667. may be executed by the current program. By default no limit is
  668. imposed. This limit is ignored by the current release.
  669.  
  670. swi(<swi-no> [ , <inregset> { , <inarg> } ]
  671.      [ ; <outregset> { , <outarg> } ] [ ; <returnreg> ]) : integer
  672. swix(<swi-no> [ , <inregset> { , <inarg> } ]
  673.      [ ; <outregset> { , <outarg> } ]) : error
  674.  
  675. calls a RISC OS SWI. swix calls the X form of the SWI, swi calls the
  676. non X form.
  677.  
  678. <swi-no> is an integer expression specifying the SWI no.,
  679. alternatively <swi-no> may be a constant string literal specifying the
  680. name of the SWI to be called, this name is looked up by the compiler
  681. at compile time and converted into the SWI no.
  682.  
  683. <inregset> is a constant register set specifying the input registers
  684. for the SWI.
  685.  
  686. Each <inarg> argument corresponds to one set element in the <inregset>
  687. from low numbered registers to high numbered registers. Each argument
  688. must be less than or equal to a machine word in size. If an array,
  689. record or string is specified as an input register the address is
  690. taken and passed to the SWI.
  691.  
  692. <outregset> is a constant register set specifying the output registers
  693. for the SWI.
  694.  
  695. Each <outarg> argument corresponds to one set element in the
  696. <outregset> from low numbered registers to high numbered registers.
  697. Each argument must be equal to a machine word in size (the compiler
  698. will pad some arguments less than a word in size to a word size).
  699.  
  700. <returnreg> specifies a register to be returned from the swi function
  701. call. If this is not specified R0 is returned by default.
  702.  
  703. swix returns type error. This is a pointer to a system error, this is
  704. set to the Nil pointer if there was no error. The type error may be
  705. used in boolean expressions yielding True if it points to an error
  706. block.
  707.  
  708. Eg:
  709.   e = swix('Wimp_Initialise', [0,1,2], 200, $4b534154, 'Test';
  710.                               [1], task_handle);
  711.  
  712. sysclock : integer
  713.  
  714. returns the number of milliseconds elapsed since this program started.
  715.  
  716. time(a)
  717.  
  718. where a is a variable of type alpha assigns the current local time to
  719. a in the form `hh:mm:ss'.
  720.  
  721. uand(x1, x2) : integer
  722.  
  723. where x1 and x2 are integer returns the bitwise and of x1 and x2. This
  724. is equivalent to x1 & x2
  725.  
  726. uor(x1, x2) : integer
  727.  
  728. where x1 and x2 are integer returns the bitwise or of x1 and x2. This
  729. is equivalent to x1 | x2 in C.
  730.  
  731. undefined(x) : boolean
  732.  
  733. where x is a real expression returns false.
  734.  
  735. unot(x) : integer
  736.  
  737. where x is integer returns the bitwise negation of x. This is
  738. equivalent to ~x in C.
  739.  
  740. uxor(x1, x2) : integer
  741.  
  742. where x1 and x2 are integer returns the bitwise exclusive or of x1 and
  743. x2. This is equivalent to x1 ^ x2 in C.
  744.  
  745. write(..., x [: n] <mode>, ...)
  746.  
  747. writeln(..., x [: n] <mode>, ...)
  748.  
  749. where x is a boolean, character or integer expression, n is an
  750. optional field width and <mode> is one of hex or oct writes the
  751. expression x in hexadecimal or octal notation respectively.
  752.  
  753. wallclock : integer
  754.  
  755. returns the time in seconds since 00:00:00 GMT, January 1, 1970.
  756.  
  757. The command line
  758. ================
  759.  
  760. The syntax of the Pascal command line is:
  761.  
  762. *pc [options] filenames
  763.  
  764. The following options are available
  765.  
  766. -iso
  767.  
  768. Compile strictly according to the ISO Pascal standard (equivalent to
  769. BS 6192 : 1982).
  770.  
  771. -c
  772.  
  773. Do not perform the Link step. This merely compiles the source
  774. program(s), leaving the object file(s) in the o directory.
  775.  
  776. -E
  777.  
  778. If this flag is specified, only the preprocessor phase of the compiler
  779. is executed. The output from this phase is sent to the standard output
  780. stream. This may be redirected to a file by using the command line
  781. output redirection. For example:
  782.  
  783. pc -E myprog > ppoutput
  784.  
  785. -C
  786.  
  787. When used in conjunction with the -E option this option specifies
  788. that comments should be included in the pre-processor output.
  789.  
  790. -D<symbol>
  791.  
  792. This option may be used to define a preprocessor symbol. These symbols
  793. may be used to conditionally compile sections of code using the #ifdef
  794. or #ifndef preprocessor constructs. The pre-processor is described in
  795. the section "Language extensions".
  796.  
  797. -U
  798.  
  799. This option may be used to undefine certain symbols which are defined
  800. automatically by the compiler, for example the symbol "__arm".
  801.  
  802. -w
  803.  
  804. Supresses the generation of warning messages
  805.  
  806. -s
  807.  
  808. If this flag is specified, no object code is generated. Instead an
  809. assembly listing of the code produced is written to s.<file>.
  810.  
  811. -g
  812.  
  813. Generate debugging tables suitable for use with the desktop debugger
  814. DDT. Object files with debugging tables must be linked with the -debug
  815. option to be usable with the debugger.
  816.  
  817. -r<mod>
  818.  
  819. Enables a selction of run time checks. Enabling these checks may add
  820. considerably to the size and speed of execution of the generated code
  821. so they should be left disabled for production software. Multiple
  822. modifiers may be specified after the -r, for example, -rarnp will
  823. enable all run time checking.
  824.  
  825. -ra
  826.  
  827. This options turns on array bound checking, if an array bound is
  828. exceeded during execution the error "Array index out of bounds" will
  829. be generated. Use the debugger to determine the location of the error.
  830.  
  831. -rn
  832.  
  833. Turns on Nil pointer checking. If a Nil pointer is referenced during
  834. execution the error "Uninitialised variable or Nil pointer referenced"
  835. will be generated. Use the debugger to determine the location of the
  836. error.
  837.  
  838. -rr
  839.  
  840. Turns on uninitialised variable checking. If an uninitialised variable
  841. reference is detected during execution the error "Uninitialised
  842. variable or Nil pointer referenced" will be generated. Use the
  843. debugger to determine the location of the error.
  844.  
  845. -rp
  846.  
  847. Enables the generation of code for assertion statements embedded in
  848. the code. If an assertion statement fails the message "*** assertion
  849. failed: <diagnostic string>, file <file>, line <line>" will be written
  850. to the standard error stream followed by a postmortem backtrace. If
  851. you are running the program from within the desktop you will need to
  852. redirect the standard error stream to a file to prevent the output
  853. being written to the graphics screen. To do this use the command line
  854. redirection facility, for example, "Run <Prog$Dir>.!Runimage
  855. 2><Prog$Dir>.ErrOutput".
  856.  
  857. -ff
  858.  
  859. Do not embed function names in the code area. The compiler does this
  860. to make the output produced by the stack backtrace function and
  861. _mapstore() more readable. Removing the names makes the code slightly
  862. smaller (typically 5%) at the expense of less meangingful backtraces
  863. and _mapstore() outputs.
  864.  
  865. -fw
  866.  
  867. Allow string literals to be writeable, as expected by some older UNIX
  868. code, by allocating them in the program's data area rather than the
  869. notionally read-only area.
  870.  
  871. You will need to use this option if you are generating code for use
  872. with the overlay manager.
  873.  
  874. -p
  875.  
  876. Generate code suitable for use with the _mapstore() and _fmapstore
  877. profiling functions in ANSILib
  878.  
  879. -zp<mod>
  880.  
  881. This option can be used to select one of the #pragma directives over
  882. a complete source module. These are described in the section on the
  883. preprocessor.
  884.  
  885. For example the option -zps1 would disable stack checking in all the
  886. functions in the source module being compiled.
  887.  
  888. Other options
  889. -------------
  890.  
  891. Other unrecognised options will be passed through to the linker. For
  892. example the -o <filename> which is used to specify the name of the
  893. image to be generated and the -l <libraries> which may be used to
  894. specify a comma separated list of libraries to be included in the link
  895. step.
  896.  
  897. Pascal and DDT
  898. ==============
  899.  
  900. To prepare a program for use with DDT specify the "Debug" option in
  901. the compiler and linker setup dialog boxes or the -g and -debug
  902. options on the compiler and linkers command line respectively.
  903.  
  904. If you are using the compiler to perform the link step you do not need
  905. to specify the debug option to the linker. The compiler will specify
  906. this when it invokes the linker.
  907.  
  908. The Pascal compiler creates a pseudo procedure 'main' which
  909. corresponds to the start of the Pascal program. DDT automatically sets
  910. a breakpoint on 'main' when it starts so just selecting continue in
  911. DDT will continue execution (through the library initialisation) until
  912. it reaches the start of your source code and then stop and display
  913. your source code.
  914.  
  915. You can display Pascal variables but there are some limitations.
  916. Global Pascal variables are not available to the debugger, local
  917. variables and procedure/function arguments are. If this causes
  918. problems you can wrap your entire program up in a single procedure and
  919. have a simple mainline which just calls this procedure. This has the
  920. effect of making all global variable local to the procedure and hence
  921. accessible by the debugger.
  922.  
  923. When entering expressions in the debugger they must be entered using C
  924. syntax as this is the only syntax the debugger understands. When the
  925. debugger displays expressions it will display them in C style syntax.
  926.  
  927. Procedures are named as <proc>.<subproc>.<subsubproc>... Procedure
  928. procb in the following would be referred to as proca.procb.
  929.  
  930. Procedure proca;
  931.  
  932. Procedure procb;
  933.  
  934. ...
  935.  
  936. Data representation
  937. ===================
  938.  
  939. This section describes how pascal objects (records, arrays etc) are
  940. represented at the machine level. This information is required if you
  941. are writing code which calls or is called by code written in other
  942. languages (for example, C or assembler).
  943.  
  944. The Pascal compiler uses the APCS-R variant of the ARM Procedure Call
  945. Standard. This has the following register bindings. The ARM Procedure
  946. Call Standard is not described here. It is described in the C Release
  947. 3 and Desktop Development Environment manuals.
  948.  
  949. sl      RN      10
  950. fp      RN      11
  951. ip      RN      12
  952. sp      RN      13
  953.  
  954. These are the same bindings as those used by C Release 3 and C Release
  955. 4. C Release 2 and ForTran 77 use different register bindings so code
  956. compiled using these compilers cannot easily be interworked with
  957. Pascal.
  958.  
  959. The following describes the machine representation for each pascal
  960. type.
  961.  
  962. Simple types:
  963. -------------
  964.  
  965. Integer
  966. -------
  967.  
  968. Integers and subranges of integers are stored as words (32 bits).
  969. These are always word aligned. The compiler will insert padding in
  970. records to ensure this. On function entry integer arguments may be
  971. stored in registers 0 to 3.
  972.  
  973. This is compatible with the C type 'int'.
  974.  
  975. Real
  976. ----
  977.  
  978. Reals are stored as two words, word aligned. On function entry a real
  979. may occupy 2 of the registers 0 to 3.
  980.  
  981. This is compatible with the C type 'double'.
  982.  
  983. Char
  984. ----
  985.  
  986. Chars and subranges of chars are stored as single bytes. On function
  987. entry these may be stored (0 extended) in registers 0 to 3. Chars
  988. which are not part of an array or record are stored in words (the
  989. unused bytes in the word are 0 padded).
  990.  
  991. Care must be taken when passing a char which is an element of an array
  992. or record by address or by reference to an external function written
  993. in another language. You must ensure that the external function does
  994. not write back a full word. If this is the case it may overwrite other
  995. elements of the array or record. In this case use a Char which is not
  996. an element of an array or record and assign it into the array or
  997. record when the procedure / function returns.
  998.  
  999. Boolean
  1000. -------
  1001.  
  1002. Booleans and subranges of booleans are stored as single bytes. False
  1003. has the ordinal value 0, True has the ordinal value 1. On function
  1004. entry these may be stored (0 extended) in registers 0 to 3. Booleans
  1005. which are not part of an array or record are stored in words (the
  1006. unused bytes in the word are 0 padded).
  1007.  
  1008. Similar care must be taken when passing Booleans which are elements of
  1009. arrays or records to functions by address or reference.
  1010.  
  1011. Text
  1012. ----
  1013.  
  1014. This uses the same representation as the compound type File of Char.
  1015.  
  1016. Compound types:
  1017. ---------------
  1018.  
  1019. Compound types are stored at word aligned addresses, no distinction is
  1020. made between packed and unpacked types.
  1021.  
  1022. The storage of conformant array formal parameters and procedure or
  1023. function formal parameters is not described here.
  1024.  
  1025. Records
  1026. -------
  1027.  
  1028. Element of records are stored at monotonically increasing addresses
  1029. within the record. These addresses are padded as necessary to fit the
  1030. alignment constraints of the record elements.
  1031.  
  1032. For variant records the maximum space is allocated to allow storage of
  1033. any variant in the variant part. If a variant descriminator is present
  1034. this is stored after all other elements of the record and before the
  1035. variant part.
  1036.  
  1037. Arrays
  1038. ------
  1039.  
  1040. Elements of arrays are stored at monotonically increasing addresses
  1041. within the array. For arrays of char an extra byte is allocated to the
  1042. storage size of the array, this byte is initialised to 0. This allows
  1043. Pascal arrays of char to be used in system and C library calls which
  1044. require 0 terminated strings.
  1045.  
  1046. Sets
  1047. ----
  1048.  
  1049. Sets are stored as bit images, each bit corresponding to one element
  1050. of the set (1 => element is present). Bits are allocated starting at
  1051. the lowest word in the set then in the lowest bit within that word.
  1052.  
  1053. Files
  1054. -----
  1055.  
  1056. Files are stored as single words containing a pointer to a
  1057. data structure within the library. This structure is compatible with
  1058. the C structure FILE. This allows Pascal file variables to be used in
  1059. calls to C file handling functions.
  1060.  
  1061. Pointers
  1062. --------
  1063.  
  1064. Pointers are stored in single words which address the object pointed
  1065. to. The value 0 is used to denote the Nil pointer.
  1066.  
  1067. Writing relocatable modules in Pascal
  1068. =====================================
  1069.  
  1070. To write a module using Pascal you will need to use the CMHG tool
  1071. provided with ANSI C Release 4. This tool construct module entry
  1072. veneers for C or Pascal code (or any APCS-R conformant code). The
  1073. CMHG tool is documented in the chapter "How to write relocatable
  1074. modules in C" in the ANSI C manual.
  1075.  
  1076. Pascal code to be included in a module must be compiled with the
  1077. Module option enabled (-zm from the command line).
  1078.  
  1079. Procedures or function which are referenced by the CMHG veneers must
  1080. be declared extern.
  1081.  
  1082. Pascal code to be included in a module must be linked with the library
  1083. 'pmodlib' instead of the library 'plib'. This library may be found in
  1084. <!PC>.o. The code must also be linked with the shared C library stubs
  1085. rather than the unshared ANSILib.
  1086.  
  1087. The CMHG entry veneers and Pascal declarations are given below. Note
  1088. that each Pascal procedure function requires a declaration and a
  1089. definition, just like a forward declaration in standard Pascal but
  1090. with the keyword 'extern' substituted for 'forward'.
  1091.  
  1092. type _kernel_swi_regs = array[0..9] of integer;
  1093.  
  1094. Run entry
  1095. ---------
  1096.  
  1097. module-is-runnable:
  1098.  
  1099. No pascal declaration. The run entry of the module will call the
  1100. mainline of you Pascal program. The arguments 'argc' and 'argv' may be
  1101. accessed through the library functions 'argc' and 'argv'.
  1102.  
  1103. Initialisation entry
  1104. --------------------
  1105.  
  1106. initialisation-code: user_init
  1107.  
  1108. function user_init(cmd_tail : string;
  1109.                    podule_base : integer;
  1110.                    pw : pointer) : error; extern;
  1111.  
  1112. Finalisation entry
  1113. ------------------
  1114.  
  1115. Finalisation entries are handled by registering a function with the C
  1116. library function 'atexit'. The registed function is called when the
  1117. module dies. The declarations for 'atexit' and the exit handler are as
  1118. follows:
  1119.  
  1120. Type atexit_handler = ^procedure exit_handler;
  1121.  
  1122. function atexit(exit_handler : atexit_handler) : integer; extern;
  1123.  
  1124. procedure exit_handler;
  1125.  
  1126. ...
  1127.  
  1128. Service calls
  1129. -------------
  1130.  
  1131. service-call-handler: sc_handler <number> <number> ...
  1132.  
  1133. procedure sc_handler(service_number : integer;
  1134.                      var r : _kernel_swi_regs;
  1135.                      pw : pointer); extern;
  1136.  
  1137. Help and command entries
  1138. ------------------------
  1139.  
  1140. command-keyword-table: cmd_handler <command-description>
  1141.  
  1142. function cmd_handler(arg_string : string;
  1143.                      argc : integer;
  1144.                      cmd_no : integer;
  1145.                      pw : pointer) : error; extern;
  1146.  
  1147. SWI handler
  1148. -----------
  1149.  
  1150. swi-handler-code: swi_handler
  1151.  
  1152. function swi_handler(swi_no : integer;
  1153.                      var r : _kernel_swi_regs;
  1154.                      pw : pointer) : error; extern;
  1155.  
  1156. SWI decoding code
  1157. -----------------
  1158.  
  1159. swi-decoding-code: swi_decoder
  1160.  
  1161. procedure swi_decode(var r : _kernel_swi_regs;
  1162.                      pw : pointer); extern;
  1163.  
  1164. IRQ handlers
  1165. ------------
  1166.  
  1167. irq-handlers: entry_name/handler_name
  1168.  
  1169. procedure entry_name; extern;
  1170.  
  1171. function handler_name(var r : _kernel_swi_regs;
  1172.                       pw : p[ointer); extern;
  1173.